package com.cqc.other.enumTest.a;

import org.junit.Test;

import java.util.EnumSet;

/**
 * @author cui
 * @description
 * @date 2022/6/3
 **/
public class EnumTest {

    /**
     * XEnum.value(枚举实例的String类型)
     */
    @Test
    public void f1() {
        SeasonEnum seasonEnum = SeasonEnum.valueOf("SUMMER");
        System.out.println(seasonEnum.getCode() + seasonEnum.getName() + seasonEnum.getTemperature());

        System.out.println(SeasonEnum.SPRING.toString());
        System.out.println(SeasonEnum.SPRING);
        System.out.println(SeasonEnum.SPRING.getName());

    }

    /**
     * XEnum.values()获取所有的枚举实例，返回数组
     */
    @Test
    public void f2() {
        SeasonEnum[] enumArray = SeasonEnum.values();
        for (SeasonEnum seasonEnum : enumArray) {
            System.out.println(seasonEnum.getCode() + seasonEnum.getName() + seasonEnum.getTemperature());
        }
        //或者，但是不建议使用
        SeasonEnum[] seasonEnums = SeasonEnum.SPRING.values();
        for (SeasonEnum anEnum : seasonEnums) {
            System.out.println(anEnum.getCode() + anEnum.getName() + anEnum.getTemperature());
        }
    }

    /**
     * EnumSet.allOf(enum.class)获取所有的枚举实例，返回EnumSet
     */
    @Test
    public void f3() {
        EnumSet<SeasonEnum> set = EnumSet.allOf(SeasonEnum.class);
        for (SeasonEnum seasonEnum : set) {
            System.out.println(seasonEnum.getCode() + seasonEnum.getName() + seasonEnum.getTemperature());
        }
    }
    @Test
    public void f4() {
        SeasonEnum.SUMMER.f1();

    }
}
